class TodoItem {
  final String id;
  final String? content;
  final bool isTop;
  final String? status;
  final bool isFavorite; // 是否关注
  final String? categoryName; // 分类名称
  final String? categoryId; // 分类ID
  final DateTime? createdTime; // 创建时间

  TodoItem({
    required this.id,
    this.content,
    this.isTop = false,
    this.status,
    this.isFavorite = false,
    this.categoryName,
    this.categoryId,
    this.createdTime,
  });

  factory TodoItem.fromJson(Map<String, dynamic> json) {
    return TodoItem(
      id: json['id'].toString(),
      content: json['content'] as String?,
      isTop: json['isTop'] as bool? ?? false,
      status: json['status'] as String?,
      isFavorite: json['isFavorite'] as bool? ?? false,
      categoryName: json['categoryName'] as String?,
      categoryId: json['categoryId']?.toString(),
      createdTime: json['createdTime'] != null
          ? DateTime.parse(json['createdTime'] as String)
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'content': content,
      'isTop': isTop,
      'status': status,
      'isFavorite': isFavorite,
      'categoryName': categoryName,
      'categoryId': categoryId,
      'createdTime': createdTime?.toIso8601String(),
    };
  }
}
